package com.ruoyi.bbs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.bbs.domain.BbsReply;
import com.ruoyi.bbs.service.IBbsReplyService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 回帖Controller
 * 
 * @author saruri
 * @date 2024-10-02
 */
@RestController
@RequestMapping("/reply")
public class BbsReplyController extends BaseController
{
    @Autowired
    private IBbsReplyService bbsReplyService;

    /**
     * 查询回帖列表
     */
    @RequiresPermissions("bbs:reply:list")
    @GetMapping("/list")
    public TableDataInfo list(BbsReply bbsReply)
    {
        startPage();
        List<BbsReply> list = bbsReplyService.selectBbsReplyList(bbsReply);
        return getDataTable(list);
    }

    /**
     * 导出回帖列表
     */
    @RequiresPermissions("bbs:reply:export")
    @Log(title = "回帖", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BbsReply bbsReply)
    {
        List<BbsReply> list = bbsReplyService.selectBbsReplyList(bbsReply);
        ExcelUtil<BbsReply> util = new ExcelUtil<BbsReply>(BbsReply.class);
        util.exportExcel(response, list, "回帖数据");
    }

    /**
     * 获取回帖详细信息
     */
    @RequiresPermissions("bbs:reply:query")
    @GetMapping(value = "/{replyId}")
    public AjaxResult getInfo(@PathVariable("replyId") Long replyId)
    {
        return success(bbsReplyService.selectBbsReplyByReplyId(replyId));
    }

    /**
     * 新增回帖
     */
    @RequiresPermissions("bbs:reply:add")
    @Log(title = "回帖", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BbsReply bbsReply)
    {
        return toAjax(bbsReplyService.insertBbsReply(bbsReply));
    }

    /**
     * 修改回帖
     */
    @RequiresPermissions("bbs:reply:edit")
    @Log(title = "回帖", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BbsReply bbsReply)
    {
        return toAjax(bbsReplyService.updateBbsReply(bbsReply));
    }

    /**
     * 删除回帖
     */
    @RequiresPermissions("bbs:reply:remove")
    @Log(title = "回帖", businessType = BusinessType.DELETE)
	@DeleteMapping("/{replyIds}")
    public AjaxResult remove(@PathVariable Long[] replyIds)
    {
        return toAjax(bbsReplyService.deleteBbsReplyByReplyIds(replyIds));
    }
}
